package abcy.cloud.blogcommon.utils;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.text.NumberFormat;

@Component
public class CodeUtil {

    public static  String codeGenerator(String sign, String code) {
        return code == null ? sign + "_0000000001" : generateCode(sign, code);

    }

    private static String generateCode(String sign, String code) {
        Integer num = Integer.parseInt(code.substring(code.substring(0, code.indexOf("_")).length()+1, code.length()));
        NumberFormat formatter = NumberFormat.getNumberInstance();
        formatter.setMinimumIntegerDigits(10);
        formatter.setGroupingUsed(false);
        code = sign + "_" + formatter.format(num+1);
        return code;
    }
}
